*Merge Kulturkampf

clear
use "Kulturkampfkalender_raw.dta"


collapse (sum) level_exact level_court level_diocese (first) district , by (municipality)

*Intensity court level
merge 1:1 municipality district using "dataset_municipalities.dta"
drop if _merge == 1
drop _merge

bysort diocese: egen oppression_level_diocese = total(level_diocese)
bysort diocese: egen inhabitants_diocese = median(inhabitants_diocese_1880) if inlist(diocese, "Trier", "Köln", "Hildesheim", "Münster", "Paderborn", "Limburg", "Fulda", "Mainz", "München und Freising")

gen oppression_diocese = 0
replace oppression_diocese = 100000*oppression_level_diocese/inhabitants_diocese if oppression_level_diocese > 0

bysort court_district: egen oppression_level_exact = total(level_exact)
bysort court_district: egen oppression_level_court = total(level_court)

gen oppression_court = oppression_level_exact+oppression_level_court

gen intensity_court = 0
replace intensity_court = 100000*oppression_court/inhabitants_court_1880+oppression_diocese


*Intensity Regierungsbezirk level

bysort admin_bezirk: egen oppression_exact_bezirk = total(level_exact)
bysort admin_bezirk: egen oppression_court_bezirk = total(level_court)

gen intensity_exact_bezirk = 0
replace intensity_exact_bezirk =  100000*oppression_exact_bezirk/catholics_bezirk_1875 if oppression_exact_bezirk > 0

gen intensity_court_bezirk = 0
replace intensity_court_bezirk = 100000*oppression_court_bezirk/catholics_bezirk_1875 if oppression_level_court > 0

gen intensity_diocese = 0
replace intensity_diocese = 100000*oppression_level_diocese/catholics_diocese_1875 if oppression_level_diocese >0

gen intensity_total = intensity_exact_bezirk+intensity_court_bezirk+intensity_diocese

gen ln_intensity = 0
replace ln_intensity = log(intensity_total+1) 

replace intensity_court = 0 if intensity_court == . & east == 0
replace ln_intensity = 0 if ln_intensity == . & east == 0

keep municipality district intensity_court ln_intensity 

merge 1:1 municipality district using "dataset_municipalities.dta"

drop _merge

save "dataset_municipalities_kulturkampf.dta", replace

